const FORMAT_FILED = "File name";
module.exports = {
    entry: async (QuickAdd, settings) => {
        // Logic here
        ({ quickAddApi } = QuickAdd)
        const templatefile = settings[FORMAT_FILED];
        // 这里是个 TAbstractFile 对象
        const tfile = app.vault.getAbstractFileByPath(templatefile);
        const isempty = Object.keys(tfile).length === 0;
        if (isempty) {
            new Notice("Empty tfile", 4000);
            return ;
        }

        // 1. 获取新的名称
        const newname = await quickAddApi.inputPrompt("输入新的文件名称:", "newname");

        // 选择要放置到那里
        const folders = app.vault
            .getAllLoadedFiles()
            .filter((f) => f.children)
            .map((f) => f.path);
        const targetFolder = await quickAddApi.suggester(folders, folders);
        if (!targetFolder) return;

        // 获取文件后缀
        const oldname = `${tfile.name}`;
        let extension = oldname.substring(oldname.lastIndexOf('.')+1);
        // 拼一个新的完整文件路径
        let newpath = `${targetFolder}/`.concat(newname, '.', extension);
        await app.vault.copy(tfile, newpath);
        app.workspace.openLinkText(newpath, "", true);
    },
    settings: {
        name: "Copy and rename",
        author: "Ding",
        options: {
            [FORMAT_FILED]: {
                type: "text",
                defaultValue: "600-Obsidian/tp/tp_empty_canvas.canvas",
                placeholder: "",
            },
        }
    },
};
